package com.tianyi.wz.walkinggame.biz;

import android.app.Activity;
import android.util.Log;

import com.qq.e.ads.rewardvideo.RewardVideoAD;
import com.qq.e.ads.rewardvideo.RewardVideoADListener;
import com.qq.e.comm.util.AdError;
import com.tianyi.wz.walkinggame.Constant;

public class TbsRewardVideoBiz implements RewardVideoADListener, IRewardVideoBiz {

    private TbsRewardVideoBiz(Activity activity,String userId,String codeId){
        mActivity = activity;
        mCodeId = codeId;
        mUserId = userId;
        init();
    }

    private RewardVideoAD rewardVideoAD;

    private Activity mActivity;
    private String mCodeId;
    private String mUserId;

    public static TbsRewardVideoBiz getInstance(Activity activity,String userId,String codeId){
        TbsRewardVideoBiz biz = new TbsRewardVideoBiz(activity,userId,codeId);
        return biz;
    }

    private void init(){
        rewardVideoAD = new RewardVideoAD(mActivity, Constant.SETTING.TBS_APPID,mCodeId,TbsRewardVideoBiz.this);

    }

    @Override
    public void showAd() {
        rewardVideoAD.loadAD();
    }

    @Override
    public void onADLoad() {
        rewardVideoAD.showAD();
        Log.d(TbsRewardVideoBiz.class.getName(),"AD Load");
    }

    @Override
    public void onVideoCached() {
        Log.d(TbsRewardVideoBiz.class.getName(),"AD Video Cached");
    }

    @Override
    public void onADShow() {
        Log.d(TbsRewardVideoBiz.class.getName(),"AD Show");
        new LogBiz(mActivity).saveAd(mUserId,mCodeId,2);
    }

    @Override
    public void onADExpose() {
        Log.d(TbsRewardVideoBiz.class.getName(),"AD Expose");
    }

    @Override
    public void onReward() {
        new RewardBiz(mActivity).reward(mUserId,Constant.SETTING.TBS_APPID,mCodeId);
        Log.d(TbsRewardVideoBiz.class.getName(),"AD Reward");
    }

    @Override
    public void onADClick() {
        Log.d(TbsRewardVideoBiz.class.getName(),"AD Video Complete");
    }

    @Override
    public void onVideoComplete() {
        Log.d(TbsRewardVideoBiz.class.getName(),"AD Video Complete");
    }

    @Override
    public void onADClose() {
        Log.d(TbsRewardVideoBiz.class.getName(),"AD close");
    }

    @Override
    public void onError(AdError adError) {
        Log.e(TbsRewardVideoBiz.class.getName(),adError.getErrorMsg());
    }
}
